% To calculate percentage from counted transtion matrices
clear all;
clc;
load 97_08_final_Q.mat
freqj=4;% 4 quarters
year_list=[1997:2009]';
year_list_text=num2str(year_list);
quarter_list=[1:12]';
quarter_list_text=num2str(quarter_list);
Rate_list=[0,1:0.5:5];
prob=zeros(13,freqj,10,13);
prob_std=zeros(13,freqj,10,12);
default_prob=zeros(length(year_list)*freqj,1);
filename='IDP_97_08_final_Q_2.xls';


% to calculate default probability for each period (month or quarter)
ij=1;
for i=1:12
    for j=1:freqj
           default_prob(ij,1)=(sum(final_result(i,j,1:5,11))/sum(final_result(i,j,1:5,13)))/(1-(sum(final_result(i,j,1:5,12))/sum(final_result(i,j,1:5,13))));
           ij=ij+1;
     end
end
xx(:,:)=default_prob(:,1); 
xlswrite(filename, xx, 'default_prob');


